home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / CBGRX103.ZIP / contrib / libgrx / src / pichar.c < prev    next >
Text File  |  1993-12-06  |  5KB  |  150 lines

  1. /**
  2.  ** PICHAR.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "p8514a.h"
  25.  
  26. static int bg_mixtable[] = {
  27.     BSS_BKGDCOL | MIX_SRC,          /* C_SET */
  28.     BSS_BKGDCOL | MIX_XOR,          /* C_XOR */
  29.     BSS_BKGDCOL | MIX_OR,          /* C_OR  */
  30.     BSS_BKGDCOL | MIX_AND          /* C_AND */
  31. };
  32.  
  33. void _GrPIDrawChar(long a,int w,int h,char far *bpt,int fg,int bg)
  34. {
  35.     if((w <= 0) || (h <= 0)) return;
  36.     if(CURC->gc_onscreen) {
  37.         int fgop = C_OPER(fg);
  38.         int bgop = C_OPER(bg);
  39.         int xpos = COORD_X(a);
  40.         int ypos = COORD_Y(a);
  41.         int bytes = ((xpos + w + 7) >> 3) - (xpos >> 3);
  42.         int shift = (xpos & 7);
  43.         int fontw = (w + 7) >> 3;
  44.  
  45.         if(((_GrPIDrawTable[fgop] ^ (fg &= C_SIGNIF)) |
  46.         (_GrPIDrawTable[bgop] ^ (bg &= C_SIGNIF))) == 0) return;
  47.         WaitQueue(7);
  48.         outpw(MULTIFUNC_CNTL,SCISSORS_L | xpos);
  49.         outpw(MULTIFUNC_CNTL,SCISSORS_R | (xpos + w - 1));
  50.         outpw(MAJ_AXIS_PCNT,((bytes << 3) - 1));
  51.         outpw(MULTIFUNC_CNTL,(MIN_AXIS_PCNT | (h - 1)));
  52.         outpw(MULTIFUNC_CNTL,(PIX_CNTL | MIXSEL_EXPPC));
  53.         outpw(FRGD_MIX,_GrPIMixTable[fgop]);
  54.         outpw(BKGD_MIX,bg_mixtable[bgop]);
  55.         WaitQueue(5);
  56.         outpw(FRGD_COLOR,fg);
  57.         outpw(BKGD_COLOR,bg);
  58.         outpw(CUR_X,(xpos & ~7));
  59.         outpw(CUR_Y,ypos);
  60.         outpw(CMD,(CMD_RECT | INC_X | INC_Y | PCDATA | _16BIT | BYTSEQ | DRAW | PLANAR | WRTDATA));
  61.         WaitQueue(8);
  62. #ifdef __TURBOC__
  63. #define _HAVE_INLINE_
  64.         asm .286
  65.         asm cld;
  66.         asm push    ds;
  67.         asm lds    si,DWORD PTR bpt;
  68.         asm mov    cx,WORD PTR shift;
  69.         asm mov    dx,PIX_TRANS;
  70.       VertLoop:
  71.         asm push    si;
  72.         asm mov    bx,WORD PTR bytes;
  73.         asm xor    ch,ch;
  74.       HorLoop:
  75.         asm lodsb
  76.         asm xor    ah,ah;
  77.         asm ror    ax,cl;
  78.         asm or    al,ch;
  79.         asm mov    ch,ah;
  80.         asm mov    ah,al;
  81.         asm add    ah,ah;
  82.         asm shr    al,3;
  83.         asm out    dx,ax;
  84.         asm dec    bx;
  85.         asm jne    HorLoop;
  86.         asm pop    si;
  87.         asm add    si,WORD PTR fontw;
  88.         asm dec    WORD PTR h;
  89.         asm jne    VertLoop;
  90.         asm pop    ds;
  91. #endif
  92. #ifdef __GNUC__
  93. #define _HAVE_INLINE_
  94.         asm volatile("                                            \n\
  95.         cld                              \n\
  96.         movl    %1,%%esi                      \n\
  97.         movl    %2,%%ecx                      \n\
  98.         movl    %3,%%edx                      \n\
  99.           L_VertLoop:                          \n\
  100.         movl    %%esi,%%edi                      \n\
  101.         movl    %4,%%ebx                      \n\
  102.         xorb    %%ch,%%ch                      \n\
  103.           L_HorLoop:                          \n\
  104.         lodsb                              \n\
  105.         xorb    %%ah,%%ah                      \n\
  106.         rorw    %%cl,%%ax                      \n\
  107.         orb    %%ch,%%al                      \n\
  108.         movb    %%ah,%%ch                      \n\
  109.         movb    %%al,%%ah                      \n\
  110.         addb    %%ah,%%ah                      \n\
  111.         shrb    $3,%%al                          \n\
  112.         outw    %%ax,%%dx                      \n\
  113.         decl    %%ebx                          \n\
  114.         jne    L_HorLoop                      \n\
  115.         movl    %5,%%esi                      \n\
  116.         leal    (%%edi,%%esi),%%esi                  \n\
  117.         decl    %0                          \n\
  118.         jne    L_VertLoop                    "
  119.         : "=g" (h)
  120.         : "g" (bpt),   "g" (shift), "g" (PIX_TRANS),
  121.           "g" (bytes), "g" (fontw)
  122.         : "di", "si", "dx", "cx", "bx", "ax"
  123.         );
  124. #endif
  125. #ifndef _HAVE_INLINE_
  126.         while(--h >= 0) {
  127.         unsigned char far *fbits;
  128.         int count,carry,bits;
  129.         fbits = (unsigned char far *)bpt;
  130.         count = bytes;
  131.         carry = 0;
  132.         while(--count >= 0) {
  133.             bits  = *fbits++ | carry;
  134.             carry = bits << 8;
  135.             bits  = (bits >> shift) & 0xff;
  136.             outpw(PIX_TRANS,((bits << 9) | (bits >> 3)));
  137.         }
  138.         bpt += fontw;
  139.         }
  140. #endif
  141.         WaitQueue(3);
  142.         outpw(MULTIFUNC_CNTL,(PIX_CNTL | 0));
  143.         outpw(MULTIFUNC_CNTL,(SCISSORS_L | 0));
  144.         outpw(MULTIFUNC_CNTL,(SCISSORS_R | 1023));
  145.         return;
  146.     }
  147.     _GrP8DrawChar(a,w,h,bpt,fg,bg);
  148. }
  149.  
  150.